import bisect
class Solution(object):
    def maximumBeauty(self, items, queries):
        items.sort()
        n = len(items)
        max_p = [0] * n
        max_p[0] = items[0][1]
        for i in range(1, n):
            max_p[i] = max(max_p[i - 1], items[i][1])
        max_val = 10 ** 9
        ans = []
        for p in queries:
            index = bisect.bisect_right(items, [p, max_val])
            if index == 0:
                ans.append(0)
            else:
                ans.append(max_p[index - 1])
        return ans
